<template>
  <Card style="margin-bottom:25px;">
    <p slot="title">
      <Icon type="md-person-add"></Icon>
      系统配置
    </p>
    <add-from ref="addForm" :form="setList" @on-success-valid="handleSubmit"></add-from>
  </Card>
</template>

<script>

import AddFrom from './setting/setFrm.vue'
import { getSystemSetting, setSystemSetting } from '@/api/system'

export default {
  data () {
    return {
      setList: {}
    }
  },
  components: {
    AddFrom
  },
  mounted: function () {
    this.getSetting()
  },
  methods: {
    handleSubmit (From) {
      setSystemSetting(From).then(res => {
        if (res.data.code === 200) {
          this.getSetting()
          this.$refs.addForm.success()// 保存成功
          this.$Message.success(res.data.message)
        } else {
          this.$refs.addForm.fail()
          this.$Message.error(res.data.error)
        }
      }).catch(err => {
        console.log(err)
        this.$refs.addForm.fail()
        this.$Message.error('保存失败')
      })
    },
    getSetting () {
      getSystemSetting().then(res => {
        const data = res.data
        if (data.code === 200) {
          this.setList = data.data
        } else {
          this.$Message.error(data.error)
        }
      }).catch(err => {
        console.log(err)
        this.$Message.error('获取系统配置信息失败')
      })
    }
  }
}
</script>
